/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.Cloudtap.UI;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import com.Cloudtap.Backend.*;


/**
 *
 * @author Dharshan
 */
class VMPanelTableModel extends AbstractTableModel {

    DataModel model;

/*     String[] columnNames = {"Name",
                                "Description",
                                "CreationTime",
                                "Operating Sytem",
                                "HardwareType"};
 */
     private Vector<String> columnNames;
     private Vector<UUID> columnIDs;
     private Vector<iVM> rows;

      Object[][] data = {
            {"Mary", "Campione",
             "Snowboarding", new Integer(5), new Boolean(false)},
            {"Alison", "Huml",
             "Rowing", new Integer(3), new Boolean(true)},
            {"Kathy", "Walrath",
             "Knitting", new Integer(2), new Boolean(false)},
            {"Sharon", "Zakhour",
             "Speed reading", new Integer(20), new Boolean(true)},
            {"Philip", "Milne",
             "Pool", new Integer(10), new Boolean(false)}
        };

    public VMPanelTableModel(DataModel model )
    {
        this.model = model;
        Hashtable<UUID,String> columns = model.GetUnionOfColumns();

        //Build the columns
        this.columnIDs = new Vector<UUID>();
        for (Enumeration e = columns.keys(); e.hasMoreElements() ;) {
            this.columnIDs.add((UUID)e.nextElement());
        }
        this.columnNames = new Vector(columns.values());

        //Build the rows
        this.rows = model.GetVMs();
    }

    public int getColumnCount() {
        return columnNames.size();
    }

    public int getRowCount() {
        return rows.size();
    }

    public String getColumnName(int col) {
        return columnNames.get(col);
    }

    public Object getValueAt(int row, int col) {
        //Get the VM
        iVM vm = rows.get(row);
        return vm.GetProperty(this.columnIDs.get(col));
    }

    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    /*
     * Don't need to implement this method unless your table's
     * editable.
     */
    public boolean isCellEditable(int row, int col) {
        return false;
    }
}

